package com.qf.mvc2203.controller;

import jdk.nashorn.internal.parser.Token;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController //所有方法都返json数据
@RequestMapping("/product")
public class ProductController {
    // 让controller带有状态了
    //HashMap<String, String> map = new HashMap<>();
    @RequestMapping("/add")
    public Map<String, String> addProduct(HttpServletRequest request) {
        //判断当前用户是否登陆过，约定登陆过的请求头中都会带有一个特殊的字段
       /* String token = request.getHeader("token");
        HashMap<String, String> map = new HashMap<>();
        if (token != null) {
            //如果token不为空，代表用户登陆过
            map.put("code", "1");
            map.put("msg", "ok");
            return map;
        } else {
            map.put("code", "-1");
            map.put("msg", "当前用户没有登录");
        }*/
        HashMap<String, String> map = new HashMap<>();
        map.put("code", "1");
        map.put("msg", "ok");
        map.put("method","add");
        return map;
    }

    @RequestMapping("/del")
    public Map<String, String> delProduct(HttpServletRequest request) {
        //判断当前用户是否登陆过，约定登陆过的请求头中都会带有一个特殊的字段
      /*  String token = request.getHeader("token");
        HashMap<String, String> map = new HashMap<>();
        if (token != null) {
            //如果token不为空，代表用户登陆过
            map.put("code", "1");
            map.put("msg", "ok");
            return map;
        } else {
            map.put("code", "-1");
            map.put("msg", "当前用户没有登录");
        }*/
        HashMap<String, String> map = new HashMap<>();
        map.put("code", "10");
        map.put("msg", "ok");
        return map;
    }
}
